package com.ferry.lock.lock.impl;

import com.ferry.lock.engine.LockEngine;
import com.ferry.lock.lock.*;

/**
 * Created by daiyong
 */
public class ReentrantReadWriteLock extends LockBase implements IReentrantReadWriteLock {

	private IReentrantReadWriteLock reentrantReadWriteLock;

	public ReentrantReadWriteLock(LockEngine lockEngine, String lockName) {
		this(lockEngine, lockName, DEFAULT_EXPIRE_TIME, DEFAULT_RETRY);
	}

	public ReentrantReadWriteLock(LockEngine lockEngine, String lockName, int expireTime) {
		this(lockEngine, lockName, expireTime, DEFAULT_RETRY);
	}

	public ReentrantReadWriteLock(LockEngine lockEngine, String lockName, int expireTime, int retry) {
		super(lockEngine, lockName, expireTime, retry);
		this.reentrantReadWriteLock = lockEngine.getReentrantReadWriteLock(lockName, expireTime, retry);
	}

	@Override
	public void switchLock() {
		this.reentrantReadWriteLock = lockEngine.getReentrantReadWriteLock(this.lockName, this.expireTime, this.retry);
	}

	@Override
	public ILock readLock() {
		return reentrantReadWriteLock.readLock();
	}

	@Override
	public ILock writeLock() {
		return reentrantReadWriteLock.writeLock();
	}

}
